/*******************************************************************************
 * Copyright (c) 2008 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.classdiagram.tabbedproperties.section;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.uml2.uml.UMLPackage;

/**
 * Enumeration to select the kind of value specification used to describe the default value 
 */
public enum ValueSpecificationKind {
	
	NONE(0, "<NONE>", null, 0),
	LITERAL_STRING(1, "LiteralString", UMLPackage.eINSTANCE.getLiteralString(), UMLPackage.LITERAL_STRING),
	LITERAL_INTEGER(2, "LiteralInteger", UMLPackage.eINSTANCE.getLiteralInteger(), UMLPackage.LITERAL_INTEGER),
	LITERAL_BOOLEAN(3, "LiteralBoolean", UMLPackage.eINSTANCE.getLiteralBoolean(), UMLPackage.LITERAL_BOOLEAN),
	LITERAL_UNLIMITED_NATURAL(4, "LiteralUnlimitedNatural", UMLPackage.eINSTANCE.getLiteralUnlimitedNatural(), UMLPackage.LITERAL_UNLIMITED_NATURAL),
	LITERAL_NULL(5, "LiteralNull", UMLPackage.eINSTANCE.getLiteralNull(), UMLPackage.LITERAL_NULL),
	OPAQUE_EXPRESSION(6, "OpaqueExpression", UMLPackage.eINSTANCE.getOpaqueExpression(), UMLPackage.OPAQUE_EXPRESSION);
	
	/** index in the table list */
	private final int index;

	/** name of the meta-class */
	private final String name;
	
	/** Meta-class to implement to create this value specification */
	private final EClass metaclass;

	/** id of the Meta-class to implement to create this value specification */
	private final int metaclassID;
	
	/** An array of all the '<em><b>ValueSpecification Kind</b></em>' enumerators. */
	private static final ValueSpecificationKind[] VALUES_ARRAY = new ValueSpecificationKind[]{NONE, LITERAL_STRING, LITERAL_INTEGER, LITERAL_BOOLEAN, LITERAL_UNLIMITED_NATURAL, LITERAL_NULL, OPAQUE_EXPRESSION};

	/** A public read-only list of all the '<em><b>ValueSpecification Kind</b></em>' enumerators. */
	public static final List<ValueSpecificationKind> VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
	
	/**
	 * Returns the '<em><b>ValueSpecification Kind</b></em>' literal with the specified literal value.
	 */
	public static ValueSpecificationKind get(String name) {
		for (int i = 0; i < VALUES_ARRAY.length; ++i) {
			ValueSpecificationKind result = VALUES_ARRAY[i];
			if (result.toString().equals(name)) {
				return result;
			}
		}
		return null;
	}
	
	/**
	 * Returns all the names of ValueSpecification kinds
	 * @return all the names of ValueSpecification kinds
	 */
	public static String[] getValueSpecificationKindNames() {
		List<String> values = new ArrayList<String>(VALUES_ARRAY.length);
		for (int i = 0; i < VALUES_ARRAY.length; ++i) {
			ValueSpecificationKind result = VALUES_ARRAY[i];
			values.add(result.getName());
		}
		return values.toArray(new String[] {});
	}

	/**
	 * Returns the '<em><b>ValueSpecification Kind</b></em>' literal with the specified name.
	 * @param name the name of the kind to retrieve
	 */
	public static ValueSpecificationKind getByName(String name) {
		for (int i = 0; i < VALUES_ARRAY.length; ++i) {
			ValueSpecificationKind result = VALUES_ARRAY[i];
			if (result.getName().equals(name)) {
				return result;
			}
		}
		return null;
	}
	
	/**
	 * Returns the '<em><b>ValueSpecification Kind</b></em>' literal with the specified metaclassID.
	 * @param metaclassID the id of the metaclass to retrieve
	 */
	public static ValueSpecificationKind getByMetaclassID(int metaclassID) {
		for (int i = 0; i < VALUES_ARRAY.length; ++i) {
			ValueSpecificationKind result = VALUES_ARRAY[i];
			if (result.getMetaclassID()==metaclassID) {
				return result;
			}
		}
		return null;
	}

	/**
	 * Returns the index of this enumeration
	 * @return the index of this enumeration
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * returns the name of this enumeration
	 * @return the name of this enumeration
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the meta-class of this enumeration
	 * @return the meta-class of this enumeration
	 */
	public EClass getMetaclass() {
		return metaclass;
	}

	/**
	 * Returns the '<em><b>ValueSpecification Kind</b></em>' literal with the specified index.
	 */
	public static ValueSpecificationKind get(int value) {
		switch (value) {
			case 0 :
				return NONE;
			case 1 :
				return LITERAL_STRING;
			case 2 :
				return LITERAL_INTEGER;
			case 3 :
				return LITERAL_BOOLEAN;
			case 4 :
				return LITERAL_UNLIMITED_NATURAL;
			case 5 :
				return LITERAL_NULL;
			case 6 :
				return OPAQUE_EXPRESSION;
		}
		return null;
	}
	
	/**
	 * Creates a new ValueSpecificationKind.
	 */
	private ValueSpecificationKind(int index, String name, EClass metaclass, int metaclassID) {
		this.index = index;
		this.name = name;
		this.metaclass = metaclass;
		this.metaclassID = metaclassID;
	}

	/**
	 * @return the metaclassID
	 */
	public int getMetaclassID() {
		return metaclassID;
	}
	
}
